<template>
  <div class="container">
    <div class="select-container">
      <el-input
        size="small"
        style="width: 200px;"
        class="filter-item"
        placeholder="输入业务系统名称"
        clearable
        v-model="bussSystemName"
        prefix-icon="el-icon-search"
      >
      </el-input>
      <el-button size="small" type="success" @click="fetchData()" style="margin-right: 10px">查 询</el-button>
    </div>
    <div class="list-container">
      <div class="filter">
        <el-row :gutter="20">
          <el-col :span="10">
            <span style="line-height: 33px;padding-left:10px;">业务系统管理</span>
          </el-col>
          <el-col :span="14" style="text-align: right;">
            <el-button size="small" type="primary" @click="createClick()" style="margin-right: 10px">创建业务系统</el-button>
          </el-col>
        </el-row>
      </div>
      <div class="data-contant">
        <div>
          <el-table
            :key='tableKey'
            :data="list.records"
            v-loading="listLoading"
            element-loading-text="给我一点时间"
            size="small"
            stripe
            style="width: 100%;border:#eeeeee"
            highlight-current-row>
            <el-table-column
              align="center"
              type="index"
              width="80"
              label="编号"
            >
            </el-table-column>
            <el-table-column
              align="center"
              label="建设单位"
              prop="developmentUnitName"
            >
            </el-table-column>

            <el-table-column
              align="center"
              label="系统名称（中文）"
              prop="chName"
            >
            </el-table-column>
            <el-table-column
              align="center"
              label="系统名称（英文）"
              prop="znName"
            >
            </el-table-column>
          
            <el-table-column
              align="center"
              label="系统负责人"
              prop="systemLeader"
            >
            </el-table-column>

            <el-table-column
              align="center"
              label="状态" :formatter="fmtLength"
              prop="status"
            >
            </el-table-column>
            <el-table-column align="center" label="操 作" width="290px" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
                <el-button type="primary" size="small" @click="handleDelete(scope.row)">删除</el-button>
                <el-button type="primary" size="small" @click="alloManagers(scope.row)">配置管理人员</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination-container">
            <el-pagination
              layout=" total, prev, pager, next"
              :page-size = "this.postList.rowBounds.limit"
              :total="this.list.count"
              @current-change="current_change"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import '@/styles/newstyle.scss'
import {
  subSysSelect,
  subSysDelete
} from '@/api/bussSystemManage/subSystemMgr'
export default {
  data() {
    return {
      dappendVisible: false,
      updateVisible: false,
      tableKey: 0,
      bussSystemName:'',
      list: {},
      postList: {
        condition: [{
          'property': 'status',
          'value': '2',
          'type': 'NE'
        }],
        sort: [{
          direction: 'DESC',
          property: 'editTime'
        }],
        rowBounds: {
          offset: 0,
          limit: 10
        }
      },
      listLoading: false,
      
      deletelist: {}
    }
  },
  // 画面刚进入method
  created() {
    this.fetchData()
    
  },
  methods: {
    fetchData() {

      this.loading = true
      /*
      var con = this.getUser()
       if(con.length==1){
         this.postList.condition.push(con[0])
       }
      */ 
      this.postList.condition.forEach(function(item, index, arr) {
          if(item.property == "chName") {
              arr.splice(index, 1);
          }
      })
     if(this.bussSystemName!=""){
        this.postList.condition.push({
          'property': 'chName',
          'value': this.bussSystemName,
          'type': 'LIKE'
        })
     }
       
      subSysSelect(this.postList).then(res => {
        this.list = res.data.data
        this.list.records = res.data.data.records
        this.loading = false
      }).catch((err) => {
        console.log(err)
      })
    },

    
    
    formatDate(datestr) {
      
      var year = datestr.slice(0, 4)
      var month = datestr.slice(4, 6)
      var date = datestr.slice(6, 8)

      return year + '-' + month + '-' + date
    },
 fmtLength(row, column) {
        const arr = row[column.property]
        /* 这里的 if(arr === undefined)
         * 是根据自己的需求，决定arr长度为0时的判断条件
         * 可以和这个不同
         */
        if (arr == '2') {
          return '已删除'
        } else if (arr == '0') {
          return '有效'
        }else if (arr == '1') {
          return '禁用'
        }
      },
    alloManagers(row) {
      
      
      this.$router.push({
        name: 'configSystemManagers',
        params: {systemId: row.id,orgId: row.developmentUnit}
      })
       
    },
    deleteData() {
      subSysDelete(this.deletelist).then(res => {
        this.fetchData()
      }).catch((err) => {
        console.log(err)
      })
    },
    handleDelete(row) {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deletelist.id = row.id
        this.deleteData()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    createClick() {
      this.$router.push({
        name: 'subSysAdd'
      })
    },
    handleEdit(row) {
      this.$router.push({
        name: 'subSysUpdate',
        params: {
          list: {
          id: row.id,
          developmentUnitName: row.developmentUnitName,
          developmentUnit: row.developmentUnit,
          chName: row.chName,
          znName: row.znName,
          status: row.status,
          constructTime: row.constructTime + " 00:00:00",
          operEndTime: row.operEndTime+ " 00:00:00",
          constructionUnit: row.constructionUnit,
          operUnit: row.operUnit,
          url: row.url,
          ip: row.ip,
          systemLeader: row.systemLeader,
          officePhone: row.officePhone,
          mobile: row.mobile,
          netArea: row.netArea
            
          }
        }
      })
    },
    current_change(currentPage) { // 通过分页获取数据
      const page = currentPage - 1
      this.postList.rowBounds.offset = page * 10
      this.fetchData()
    },
    
    /*
    getUser(){
      var flag=0
      var conditionEx = []
      for (let i = 0; i < this.$store.getters.roles.length; i++) {
          if (this.$store.getters.roles[i].code == "SYS_ADMIN") {
            //alert(this.$store.getters.roles[i].code)
            flag=1
            break
          }
      }
      if(flag==0){
        conditionEx.push({
          'property': 'addUser',
          'value': this.$store.getters.userid,
          'type': 'EQ'
        });
      }
      return conditionEx
    }
    */
  }
}
</script>

<style scoped>
  .container{
    color: #3b96f3;
    background: #fff;
    padding: 20px;
    height: 100%;
    overflow-y: auto;
  }
  .select-container{
    padding: 10px 10px;
    margin-bottom: 10px;
    border-radius: 4px;
    border: 1px solid #eeeeee;
  }
  .list-container{
    margin-top:30px;
    padding:0 10px 10px 10px;
    border:1px solid#eeeeee;
    border-radius: 4px;
  }
  .data-contant{
    background-color: rgba(0,0,0,.035);
    padding: 30px 10px 20px;
  }
  .data-detail{
    font-size: 14px;
    padding:20px 0;
    text-align: center;
  }
  .data-title{
    font-size: 14px;
    padding:10px 0;
    text-align: center;
  }
  .data-title div{
    font-size: 14px;
    padding:5px 0;
  }
  .filter{
    padding: 10px 5px;
    border-bottom: 2px solid#eeeeee;
  }
  .list-container{
  }
  .bold{
    font-weight: bold;
  }
</style>
